package com.ruoyi.activity.service.impl;

import java.util.List;

import com.ruoyi.activity.mapper.TbUserCouponMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.activity.mapper.TbChannelMapper;
import com.ruoyi.activity.domain.TbChannel;
import com.ruoyi.activity.service.ITbChannelService;

import javax.annotation.Resource;

/**
 * 渠道Service业务层处理
 * 
 * @author jll
 * @date 2025-06-15
 */
@Service
public class TbChannelServiceImpl implements ITbChannelService 
{
    @Autowired
    private TbChannelMapper tbChannelMapper;

    @Resource
    private TbUserCouponMapper tbUserCouponMapper;

    /**
     * 查询渠道
     * 
     * @param id 渠道主键
     * @return 渠道
     */
    @Override
    public TbChannel selectTbChannelById(Long id)
    {
        return tbChannelMapper.selectTbChannelById(id);
    }

    /**
     * 查询渠道列表
     * 
     * @param tbChannel 渠道
     * @return 渠道
     */
    @Override
    public List<TbChannel> selectTbChannelList(TbChannel tbChannel)
    {
        List<TbChannel> tbChannels = tbChannelMapper.selectTbChannelList(tbChannel);
        for (TbChannel channel : tbChannels) {
            channel.setCancelNumber(tbUserCouponMapper.selectTbUserCouponCancel(null, channel.getId()));
        }
        return tbChannels;
    }

    /**
     * 新增渠道
     * 
     * @param tbChannel 渠道
     * @return 结果
     */
    @Override
    public int insertTbChannel(TbChannel tbChannel)
    {
        tbChannel.setCreateTime(DateUtils.getNowDate());
        return tbChannelMapper.insertTbChannel(tbChannel);
    }

    /**
     * 修改渠道
     * 
     * @param tbChannel 渠道
     * @return 结果
     */
    @Override
    public int updateTbChannel(TbChannel tbChannel)
    {
        tbChannel.setUpdateTime(DateUtils.getNowDate());
        return tbChannelMapper.updateTbChannel(tbChannel);
    }

    /**
     * 批量删除渠道
     * 
     * @param ids 需要删除的渠道主键
     * @return 结果
     */
    @Override
    public int deleteTbChannelByIds(Long[] ids)
    {
        return tbChannelMapper.deleteTbChannelByIds(ids);
    }

    /**
     * 删除渠道信息
     * 
     * @param id 渠道主键
     * @return 结果
     */
    @Override
    public int deleteTbChannelById(Long id)
    {
        return tbChannelMapper.deleteTbChannelById(id);
    }
}
